// checkSignature.js
const crypto = require('crypto');

module.exports = (req, res) => {
    console.log(req);
    console.log(req.query);
    const q = req.query;
    const signature = q.signature;
    const token = 'cw141313';
    const echostr = q.echostr;
    const timestamp = q.timestamp;
    const nonce = q.nonce;
    const array = new Array(token, timestamp, nonce);
    array.sort;
    var key = [token, timestamp, nonce].sort().join('');
    var sha1 = require('crypto').createHash('sha1');
    sha1.update(key);
    let _signature = sha1.digest('hex')
    // console.log(_signature);
    
    if (_signature == signature) {
        res.send(echostr);
    } else {
        res.send('....');
    }
}
